package org.itworks.biodev.gui.panels;

import java.util.Observable;
import java.util.Vector;

import org.itworks.biodev.model.*;
import org.itworks.helpers.MVCNotification;

public class SalesPanelModel extends Observable {
	
	private Vector<Sale> sales;
	private Vector<ProductSale> products;
	
	public void setSalesList(Vector<Sale> sales) {
		this.setChanged();
		this.sales = sales;
		this.notifyObservers(new MVCNotification(SalesPanelView.FILL_SALES_TABLE, sales));
		this.clearChanged();
	}
	
	public void setProductsList(Sale sale) {
		try {
			this.setChanged();
			this.notifyObservers(new MVCNotification(SalesPanelView.FILL_SALE_ID_LABEL, "Commande "+sale.getId().toString()));
			this.clearChanged();
		} catch (Exception e) {
			e.printStackTrace();
		}
		try {
			this.setChanged();
			this.products = ProductSaleTable.getInstance().findProductBySale(sale);
			this.notifyObservers(new MVCNotification(SalesPanelView.FILL_SALE_DETAILS_TABLE, products));
			this.clearChanged();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public Vector<Sale> getSales() {
		return sales;
	}
	
	public Vector<ProductSale> getProducts() {
		return products;
	}
}
